package org.cqut.system.work_content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.cqut.system.common.dto.WorkDto;
import org.cqut.system.work_content.domain.WorkContent;
import org.cqut.system.work_content.service.WorkContentService;
import org.cqut.system.work_content.mapper.WorkContentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author XiAoXu
 */
@Service
public class WorkContentServiceImpl extends ServiceImpl<WorkContentMapper, WorkContent>
        implements WorkContentService {
    @Autowired
    private WorkContentMapper workContentMapper;

    @Override
    public List<WorkContent> workList(String courseId) {
        QueryWrapper<WorkContent> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id", courseId);
        return workContentMapper.selectList(queryWrapper);
    }

    @Override
    public boolean saveWork(String path, WorkDto workDto) {
        WorkContent workContent = new WorkContent();
        workContent.setContentPath(path);
        workContent.setContentStartTime(workDto.getDate()[0]);
        workContent.setContentEndTime(workDto.getDate()[1]);
        workContent.setCourseId(workDto.getCourseId());
        workContent.setWorkName(workDto.getWorkName());
        return save(workContent);
    }
}




